import {createStore} from 'vuex'

export default createStore({
    state: {
        token: localStorage.getItem("token"),
        userInfo: JSON.parse(localStorage.getItem("userInfo")),
        courseId: sessionStorage.getItem("courseId"),
    },
    mutations: {
        SET_TOKEN: (state, token) => {
            state.token = token;
            localStorage.setItem("token", token)
        },
        SET_USERINFO: (state, userInfo) => {
            state.userInfo = userInfo;
            localStorage.setItem("userInfo", JSON.stringify(userInfo));
        },

        REMOVE_INFO: (state) => {
            state.token = '';
            state.userInfo = {};
            state.userType = {};
            localStorage.setItem("token", '');
            localStorage.setItem("userInfo", JSON.stringify(''));
            localStorage.setItem("userType", JSON.stringify(''));
        },
        SET_USERTYPE:(state, userType)=>{
            state.userType = userType;
            localStorage.setItem("userType", JSON.stringify(userType));
        },


        // LOGIN_OUT(){
        //
        // }
    },
    getters: {
        // eslint-disable-next-line
        getUser: state => {
            return this.state.userInfo;
        },//是不是第一次登录
        getToken: state => {
            if (state.token == null) {
                return '';
            } else {
                return state.token;
            }
        },
    },
    actions: {},
})
